#ifndef WDT_H_
#define WDT_H_

#include <targets/lpc2378.h>

#define WDT_MODE_DEBUG() {WDMOD &= ~WDMOD_WDRESET_MASK;}
#define WDT_MODE_RESET() {WDMOD |= WDMOD_WDRESET_MASK;}

#define WDT_ENABLE(ticks) {WDMOD |= WDMOD_WDEN_MASK; WDTC = (ticks);}
/** Could not disable watchdog after enabling */
#define WDT_DISABLE() {WD_MOD &= ~WDMOD_WDEN_MASK;}

#define WDT_IS_RESET() ((WDMOD & WDMOD_WDTOF_MASK) > 0)
#define WDT_IS_RESET_CLR() {WDMOD &= ~WDMOD_WDTOF_MASK;}

#define WDT_RESET() {ctl_global_interrupts_disable(); WDFEED = 0xAA; WDFEED = 0x55; ctl_global_interrupts_enable();}

/* Example:
 * Do not forget to enable #define STARTUP_FROM_RESET in 
 *

  if (!WDT_IS_RESET()) {
    led_red_off(); led_yellow_off();
  }
  else 
  {
    
    led_red_off(); led_yellow_off();
  }
  delay_ms(1000);
  WDT_MODE_RESET();
  WDT_ENABLE(0x7fffff8); //1 minute timeout
  WDT_RESET();
  
  while(1) {
  //WDT_RESET();
  led_red_on(); led_yellow_on();
  }
*/


#endif